"use strict";

var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var useref = require('gulp-useref');
var useref = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
// var cache = require('gulp-cache');
var del = require('del');
var runSequence = require('run-sequence');

gulp.task('sass', function () {
  return gulp.src('./src/sass/*.scss')
    .pipe(autoprefixer())
    .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
    .pipe(gulp.dest('./bulid/css'));
});

gulp.task('useref', function(){
  return gulp.src('./src/*.html')
    .pipe(useref())
    .pipe(uglify())
    .pipe(gulp.dest('bulid'));
});

gulp.task('browserSync', function() {
  browserSync({
    server: { baseDir: 'bulid' },
  })
});

gulp.task('default',['sass','useref'], function () {
  console.log('Working!!!');
});

gulp.task('work', function () {
  gulp.watch('./src/sass/*.scss', ['sass'], browserSync.reload({ stream: true }));
});

// http://www.open-open.com/lib/view/open1426232157888.html 插件合集